#include "input.h"

ORGSSBool *ORGSSKeyboardState [2];

VALUE ORGSSInputTrigger ( int argc, VALUE *argv, VALUE self ) {
	int l;
	char *p;
	char c;
	
	while ( argc-- ) {
		l = RSTRING(argv[argc])->len;
		p = RSTRING(argv[argc])->ptr;
		
		while ( l-- ) {
			c = p[l];
			
			if ( ORGSSKeyboardState[0][c] && ! ORGSSKeyboardState[1][c] ) {
				return Qtrue;
			}
		}
	}
	
	return Qfalse;
}

VALUE ORGSSInputRelease ( int argc, VALUE *argv, VALUE self ) {
	int l;
	char *p;
	char c;
	
	while ( argc-- ) {
		l = RSTRING(argv[argc])->len;
		p = RSTRING(argv[argc])->ptr;
		
		while ( l-- ) {
			c = p[l];
			
			if ( ORGSSKeyboardState[1][c] && ! ORGSSKeyboardState[0][c] ) {
				return Qtrue;
			}
		}
	}
	
	return Qfalse;
}

VALUE ORGSSInputPress ( int argc, VALUE *argv, VALUE self ) {
	int l;
	char *p;
	char c;
	
	while ( argc-- ) {
		l = RSTRING(argv[argc])->len;
		p = RSTRING(argv[argc])->ptr;
		
		while ( l-- ) {
			c = p[l];
			
			if ( ORGSSKeyboardState[0][c] ) {
				return Qtrue;
			}
		}
	}
	
	return Qfalse;
}